import { requestUrl } from "../config";

/**
 * 图片上传 formdata形式
 */
export const upload = (params) => {
  const url = 'https://m.aiymh.com/v1/user/upload';
  // let params = {parentId: "0", text: this.state.textContent, postType: 0, profitType: 0}

  const formdata = new FormData();
  formdata.append('sign', 'qoMIdTwkeKf6t1mzTlhaWfQrtuY=');
  // formdata.append('file', {uri: params.uri, type: 'image/jpg', name: params.fileName});
  formdata.append('file', {
    uri: params.uri,
    type: 'image/jpeg',
    name: params.fileName,
  });
  // formdata.append('file', {uri: params.uri, type: 'multipart/form-data', name: 'image.png' });

  fetch(url, {
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data; boundary=---7d4a6d158c9',
      Charset: 'UTF-8',
      Connection: 'Keep-Alive',
      token: 'eafac359-00ed-4dad-bcd1-4152233c9cd4',
    },
    body: formdata,
  })
    .then((response) => {
      console.log('image uploaded');
    })
    .catch((err) => {
      console.log(err);
      alert('失败');
    });
};
